home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / utmisc2 / onehand.lzh / OneHand / OneHand.mod < prev   
Text File  |  1995-11-20  |  11KB  |  410 lines

  1.  
  2. (* ------------------------------------------------------------------------
  3.   :Program.       OneHand
  4.   :Contents.      Qualifies keyboard and mouse actions.
  5.   :Author.        Kamran Karimi
  6.   :Address.       89-Nastaran/Ghandehari
  7.   :Address.       Khosh Shomali str.
  8.   :Address.       14578 - Tehran
  9.   :Address.       IRAN 
  10.   :Addrees.       Internet: karimik@sun.iust.ac.ir
  11.   :Copyright.     Source and executable copyrighted, but can be used 
  12.   :Copyright.     with no charges     
  13.   :Language.      Oberon and Assembly
  14.   :Translator.    AMIGA OBERON V3.00d, SAS/C 6.00 assembler
  15.   :History.       V1.0 
  16. ------------------------------------------------------------------------ *)
  17.  
  18. MODULE OneHand;
  19.  
  20. IMPORT I:Intuition, SYS:SYSTEM,e:Exec,g:Graphics,
  21.        input:Input,d:Dos,es:ExecSupport;
  22.  
  23. TYPE
  24.  PointType = ARRAY 3 OF ARRAY 2 OF INTEGER;
  25.  
  26. CONST
  27.  title = "OneHand! V1.0";
  28.  NumKeys = 8;
  29.  LShiftID = 0;
  30.  RShiftID = 1;
  31.  CapsID = 2;
  32.  CtrlID = 3;
  33.  LAltID = 4;
  34.  RAltID = 5;
  35.  LAmigaID = 6;
  36.  RAmigaID = 7;
  37.  ScrSwitchID = 8;
  38.  
  39.  winWidth = 210;
  40.  winHeight = 57;
  41.  bigGadWidth = 55;
  42.  bigGadHeight = 10;
  43.  gadWidth = 35;
  44.  gadHeight = 10;
  45.  smalGadWidth = 13;
  46.  smalGadHeight = 10;
  47.  firstRow = 14;
  48.  secondRow = 28;
  49.  thirdRow = 42;
  50.  
  51.  
  52.  normalStyle = g.TextAttr(SYS.ADR("topaz.font"),8,
  53.                                             g.normal,SHORTSET{g.romFont});
  54.  
  55.  italicStyle = g.TextAttr(SYS.ADR("topaz.font"),8,
  56.                                   SHORTSET{g.italic},SHORTSET{g.romFont});
  57.  
  58.  shifText = I.IntuiText(1,0,g.jam2,7,1,SYS.ADR(normalStyle),
  59.                                                         SYS.ADR("^"),NIL);
  60.  
  61.  capsText = I.IntuiText(1,0,g.jam2,2,2,SYS.ADR(normalStyle),
  62.                                                       SYS.ADR("Caps"),NIL);
  63.  
  64.  ctrlText = I.IntuiText(1,0,g.jam2,2,2,SYS.ADR(normalStyle),
  65.                                                       SYS.ADR("Ctrl"),NIL);
  66.  
  67.  altText = I.IntuiText(1,0,g.jam2,6,2,SYS.ADR(normalStyle),
  68.                                                        SYS.ADR("Alt"),NIL);
  69.  
  70.  amigaText = I.IntuiText(1,0,g.jam2,12,2,SYS.ADR(italicStyle),
  71.                                                          SYS.ADR("A"),NIL);
  72.  
  73.  scrswitchText = I.IntuiText(1,0,g.jam2,2,2,SYS.ADR(normalStyle),
  74.                                                          SYS.ADR("X"),NIL);
  75.  
  76.  myText =  I.IntuiText(2,0,g.jam2,72,14,SYS.ADR(italicStyle),
  77.                                           SYS.ADR("By Kamran Karimi"),NIL);
  78.  
  79.  bigBrightPoints = PointType(0,bigGadHeight + 1,0,0,bigGadWidth,0);
  80.  
  81.  bigDarkPoints = PointType(bigGadWidth,0,bigGadWidth,bigGadHeight + 1,
  82.                                                        0,bigGadHeight + 1);
  83.  
  84.  smalBrightPoints = PointType(0,smalGadHeight + 1,0,0,smalGadWidth,0);
  85.  
  86.  smalDarkPoints = PointType(smalGadWidth,0,smalGadWidth,smalGadHeight + 1,
  87.                                                       0,smalGadHeight + 1);
  88.  
  89.  brightPoints = PointType(0,gadHeight + 1,0,0,gadWidth,0);
  90.  
  91.  darkPoints = PointType(gadWidth,0,gadWidth,gadHeight + 1,0,gadHeight + 1);
  92.  
  93.  
  94. VAR
  95.  inputHandler : e.Interrupt;
  96.  Port : e.MsgPortPtr;
  97.  keyReq : e.IOStdReqPtr;
  98.  
  99.  OneHandnw : I.NewWindow;
  100.  OneHandw : I.WindowPtr;
  101.  
  102.  LShift,RShift,Caps,Ctrl,LAlt,RAlt,LAmiga,RAmiga,ScrSwitch : I.Gadget;
  103.  gadptr : I.GadgetPtr;
  104.  
  105.  imsgClass : LONGSET;
  106.  imsg : I.IntuiMessagePtr;
  107.  
  108.  dark,bright,Seldark,Selbright : I.Border;
  109.  smalDark,smalBright,smalSeldark,smalSelbright : I.Border;
  110.  bigDark,bigBright,bigSeldark,bigSelbright : I.Border;
  111.  
  112.  onColor,offColor : SHORTINT;
  113.  
  114.  lampText : I.IntuiText;
  115.  
  116.  Qualify["Qualify"] : ARRAY NumKeys OF INTEGER; (* see ForceQualify.asm *)
  117.  
  118.  
  119.  
  120. PROCEDURE ForceQualify{"ForceQualify"}; (* see file ForceQualify.asm *)
  121.  
  122.  
  123. PROCEDURE Init(); (* is there a better (shorter) way of initialization? *)
  124. BEGIN
  125.  
  126.  smalBright.leftEdge := -1;
  127.  smalBright.topEdge := -1;
  128.  smalBright.frontPen := 2;
  129.  smalBright.backPen := 0;
  130.  smalBright.drawMode := g.jam1;
  131.  smalBright.count := 3;
  132.  smalBright.xy := SYS.ADR(smalBrightPoints);
  133.  smalBright.nextBorder := SYS.ADR(smalDark);
  134.  
  135.  smalDark := smalBright;
  136.  smalDark.frontPen := 1;
  137.  smalDark.xy := SYS.ADR(smalDarkPoints);
  138.  smalDark.nextBorder := NIL;
  139.  
  140.  smalSelbright := smalBright;
  141.  smalSelbright.frontPen := 1;
  142.  smalSelbright.xy := SYS.ADR(smalBrightPoints);
  143.  smalSelbright.nextBorder := SYS.ADR(smalSeldark);
  144.  
  145.  smalSeldark := smalBright;
  146.  smalSeldark.frontPen := 2;
  147.  smalSeldark.xy := SYS.ADR(smalDarkPoints);
  148.  smalSeldark.nextBorder := NIL;
  149.  
  150.  bigBright := smalBright;
  151.  bigBright.frontPen := 2;
  152.  bigBright.xy := SYS.ADR(bigBrightPoints);
  153.  bigBright.nextBorder := SYS.ADR(bigDark);
  154.  
  155.  bigDark := smalBright;
  156.  bigDark.frontPen := 1;
  157.  bigDark.xy := SYS.ADR(bigDarkPoints);
  158.  bigDark.nextBorder := NIL;
  159.  
  160.  bigSelbright := smalBright;
  161.  bigSelbright.frontPen := 1;
  162.  bigSelbright.xy := SYS.ADR(bigBrightPoints);
  163.  bigSelbright.nextBorder := SYS.ADR(bigSeldark);
  164.  
  165.  bigSeldark := smalBright;
  166.  bigSeldark.frontPen := 2;
  167.  bigSeldark.backPen := 0;
  168.  bigSeldark.xy := SYS.ADR(bigDarkPoints);
  169.  bigSeldark.nextBorder := NIL;
  170.  
  171.  bright := smalBright;
  172.  bright.frontPen := 2;
  173.  bright.xy := SYS.ADR(brightPoints);
  174.  bright.nextBorder := SYS.ADR(dark);
  175.  
  176.  dark := smalBright;
  177.  dark.frontPen := 1;
  178.  dark.xy := SYS.ADR(darkPoints);
  179.  dark.nextBorder := NIL;
  180.  
  181.  Selbright := smalBright;
  182.  Selbright.frontPen := 1;
  183.  Selbright.xy := SYS.ADR(brightPoints);
  184.  Selbright.nextBorder := SYS.ADR(Seldark);
  185.  
  186.  Seldark := smalBright;
  187.  Seldark.frontPen := 2;
  188.  Seldark.backPen := 0;
  189.  Seldark.xy := SYS.ADR(darkPoints);
  190.  Seldark.nextBorder := NIL;
  191.  
  192.  OneHandnw.leftEdge := 100;
  193.  OneHandnw.topEdge := 50;
  194.  OneHandnw.flags := LONGSET{I.windowDrag,I.windowDepth,I.windowClose};
  195.  OneHandnw.idcmpFlags := LONGSET{I.gadgetUp,I.closeWindow};
  196.  OneHandnw.type := {I.wbenchScreen};
  197.  OneHandnw.width := winWidth;
  198.  OneHandnw.height := winHeight;
  199.  OneHandnw.firstGadget := SYS.ADR(LShift);
  200.  OneHandnw.title := SYS.ADR(title);
  201.  
  202.  LShift.nextGadget := SYS.ADR(RShift);
  203.  LShift.leftEdge := 15;
  204.  LShift.topEdge := secondRow;
  205.  LShift.width := bigGadWidth;
  206.  LShift.height := bigGadHeight;
  207.  LShift.gadgetText := SYS.ADR(shifText);
  208.  LShift.gadgetRender := SYS.ADR(bigBright);
  209.  LShift.selectRender := SYS.ADR(bigSelbright);
  210.  LShift.flags      := {I.gadgHImage};
  211.  LShift.gadgetType := I.boolGadget;
  212.  LShift.activation  := {I.relVerify,I.toggleSelect};
  213.  LShift.gadgetID := LShiftID;
  214.  
  215.  RShift := LShift;
  216.  RShift.nextGadget := SYS.ADR(Caps);
  217.  RShift.leftEdge := 145;
  218.  RShift.gadgetID := RShiftID;
  219.  
  220.  Caps := LShift;
  221.  Caps.nextGadget := SYS.ADR(Ctrl);
  222.  Caps.leftEdge := 80;
  223.  Caps.topEdge := secondRow;
  224.  Caps.gadgetText := SYS.ADR(capsText);
  225.  Caps.activation  := {I.relVerify};
  226.  Caps.gadgetID := CapsID;
  227.  
  228.  Ctrl.nextGadget := SYS.ADR(LAlt);
  229.  Ctrl.leftEdge := 15;
  230.  Ctrl.topEdge := firstRow;
  231.  Ctrl.width := gadWidth;
  232.  Ctrl.height := gadHeight;
  233.  Ctrl.gadgetText := SYS.ADR(ctrlText);
  234.  Ctrl.gadgetRender := SYS.ADR(bright);
  235.  Ctrl.selectRender := SYS.ADR(Selbright);
  236.  Ctrl.flags      := {I.gadgHImage};
  237.  Ctrl.gadgetType := I.boolGadget;
  238.  Ctrl.activation  := {I.relVerify,I.toggleSelect};
  239.  Ctrl.gadgetID := CtrlID;
  240.  
  241.  LAlt := Ctrl;
  242.  LAlt.nextGadget := SYS.ADR(RAlt);
  243.  LAlt.leftEdge := 10;
  244.  LAlt.topEdge := thirdRow;
  245.  LAlt.gadgetText := SYS.ADR(altText);
  246.  LAlt.gadgetID := LAltID;
  247.  
  248.  RAlt := Ctrl;
  249.  RAlt.nextGadget := SYS.ADR(LAmiga);
  250.  RAlt.leftEdge := 165;
  251.  RAlt.topEdge := thirdRow;
  252.  RAlt.gadgetText := SYS.ADR(altText);
  253.  RAlt.gadgetID := RAltID;
  254.  
  255.  LAmiga := Ctrl;
  256.  LAmiga.nextGadget := SYS.ADR(RAmiga);
  257.  LAmiga.leftEdge := 50;
  258.  LAmiga.topEdge := thirdRow;
  259.  LAmiga.gadgetText := SYS.ADR(amigaText);
  260.  LAmiga.gadgetID := LAmigaID;
  261.  
  262.  RAmiga := Ctrl;
  263.  RAmiga.nextGadget := SYS.ADR(ScrSwitch);
  264.  RAmiga.leftEdge := 125;
  265.  RAmiga.topEdge := thirdRow;
  266.  RAmiga.gadgetText := SYS.ADR(amigaText);
  267.  RAmiga.gadgetID := RAmigaID;
  268.  
  269.  ScrSwitch := Ctrl;
  270.  ScrSwitch.nextGadget := NIL;
  271.  ScrSwitch.leftEdge := 100;
  272.  ScrSwitch.topEdge := thirdRow;
  273.  ScrSwitch.width := smalGadWidth;
  274.  ScrSwitch.height := smalGadHeight;
  275.  ScrSwitch.gadgetRender := SYS.ADR(smalBright);
  276.  ScrSwitch.selectRender := SYS.ADR(smalSelbright);
  277.  ScrSwitch.activation  := {I.relVerify};
  278.  ScrSwitch.gadgetText := SYS.ADR(scrswitchText);
  279.  ScrSwitch.gadgetID := ScrSwitchID;
  280.  
  281.  onColor := 2;
  282.  offColor := 1;
  283.  
  284.  IF e.exec.libNode.version < 36 THEN
  285.   bright.frontPen := 1;
  286.   dark.frontPen := 2;
  287.   Selbright.frontPen := 2;
  288.   Seldark.frontPen := 1;
  289.   smalBright.frontPen := 1;
  290.   smalDark.frontPen := 2;
  291.   smalSelbright.frontPen := 2;
  292.   smalSeldark.frontPen := 1;
  293.   bigBright.frontPen := 1;
  294.   bigDark.frontPen := 2;
  295.   bigSelbright.frontPen := 2;
  296.   bigSeldark.frontPen := 1;
  297.   OneHandnw.detailPen := 0;
  298.   OneHandnw.blockPen := 1;
  299.   onColor := 1;
  300.   offColor := 2;
  301.  END;
  302.  
  303.  lampText.frontPen := offColor;
  304.  lampText.backPen := 0;
  305.  lampText.drawMode := g.jam2;
  306.  lampText.leftEdge := 120;
  307.  lampText.topEdge := 28;
  308.  lampText.iTextFont := SYS.ADR(normalStyle);
  309.  lampText.iText := SYS.ADR("*");
  310.  lampText.nextText := NIL;
  311.  
  312. END Init;
  313.  
  314.  
  315. PROCEDURE InstallHandler():BOOLEAN;
  316. VAR
  317.  res : SHORTINT;
  318.  ret : BOOLEAN;
  319.  
  320. BEGIN
  321.  ret := TRUE;
  322.  Port := es.CreatePort("",0);
  323.  IF Port # NIL THEN
  324.   keyReq := es.CreateExtIO(Port,SIZE(e.IOStdReq));
  325.   IF keyReq # NIL THEN
  326.    IF e.OpenDevice("input.device",0,keyReq,LONGSET{}) = 0 THEN
  327.     inputHandler.code := ForceQualify;
  328.     inputHandler.data := NIL;
  329.     inputHandler.node.pri := 127;
  330.     keyReq.command := input.addHandler;
  331.     keyReq.data := SYS.ADR(inputHandler);
  332.     res := e.DoIO(keyReq);
  333.    ELSE ret := FALSE; END;
  334.   ELSE ret := FALSE; END;
  335.  ELSE ret := FALSE; END;
  336.  RETURN ret;
  337. END InstallHandler;
  338.  
  339.  
  340. PROCEDURE RemoveHandler();
  341. VAR
  342.  res : SHORTINT;
  343.  
  344. BEGIN
  345.  keyReq.command := input.remHandler;
  346.  keyReq.data := SYS.ADR(inputHandler);
  347.  res := e.DoIO(keyReq);
  348.  e.CloseDevice(keyReq);
  349.  es.DeleteExtIO(keyReq);
  350.  es.DeletePort(Port);
  351. END RemoveHandler; 
  352.  
  353.  
  354. PROCEDURE HandleScrSwitch();
  355. VAR
  356.  IBase : LONGINT;
  357.  
  358. BEGIN
  359.  I.CloseWindow(OneHandw);
  360.  d.Delay(200);
  361.  OneHandnw.type := I.customScreen;
  362.  IBase := I.LockIBase(0);
  363.  OneHandnw.screen := I.int.firstScreen;
  364.  I.UnlockIBase(IBase);
  365.  OneHandw := I.OpenWindow(OneHandnw);
  366.  IF OneHandw = NIL THEN  RemoveHandler(); HALT(20); END;
  367.  I.PrintIText(OneHandw.rPort,myText,0,0);
  368.  I.PrintIText(OneHandw.rPort,lampText,0,0);
  369. END HandleScrSwitch;
  370.  
  371.  
  372. PROCEDURE HandleCaps();
  373. BEGIN
  374.  IF Qualify[CapsID] = 0 THEN
  375.   lampText.frontPen := onColor;
  376.   I.PrintIText(OneHandw.rPort,lampText,0,0);
  377.   Qualify[CapsID] := 1;
  378.  ELSE
  379.   lampText.frontPen := offColor;
  380.   I.PrintIText(OneHandw.rPort,lampText,0,0);
  381.   Qualify[CapsID] := 0;
  382.  END;
  383. END HandleCaps;
  384.  
  385.  
  386. BEGIN
  387.  Init();
  388.  OneHandw := I.OpenWindow(OneHandnw);
  389.  IF OneHandw = NIL THEN HALT(20); END;
  390.  IF InstallHandler() = FALSE THEN
  391.   I.CloseWindow(OneHandw);
  392.   HALT(20);
  393.  END;
  394.  I.PrintIText(OneHandw.rPort,myText,0,0);
  395.  I.PrintIText(OneHandw.rPort,lampText,0,0);
  396.  LOOP
  397.   e.WaitPort(OneHandw.userPort);
  398.   imsg := e.GetMsg(OneHandw.userPort);
  399.   imsgClass := imsg.class;
  400.   gadptr := imsg.iAddress;
  401.   e.ReplyMsg(imsg);
  402.   IF (I.gadgetUp IN imsgClass) THEN
  403.    IF gadptr.gadgetID = ScrSwitchID THEN HandleScrSwitch();
  404.    ELSIF gadptr.gadgetID = CapsID THEN HandleCaps();
  405.    ELSIF I.selected IN gadptr.flags THEN Qualify[gadptr.gadgetID] := 1;
  406.    ELSE  Qualify[gadptr.gadgetID] := 0; END;
  407.   ELSE I.CloseWindow(OneHandw); RemoveHandler(); EXIT; END;
  408.  END;
  409. END OneHand.
  410.